// 用户数据
import request from "@/utils/request.js";

const mockUser = {
    id: 1,
    nickname: '张三',
    avatar: 'https://example.com/avatar1.jpg',
    phone: '13800138000'
}

//用户注册
export const register = async (params) => {
    return await request.post("/user/register", params)
}
// 登录
export const login = async (phone, code) => {
    await new Promise(resolve => setTimeout(resolve, 500))
    // 模拟验证码检查
    if (code !== '123456') {
        throw new Error('验证码错误')
    }
    return {
        token: 'mock_token_' + Date.now(),
        user: mockUser
    }
}

// 账号密码登录
export const loginByPassword = async (params) => {
    const {data} = await request.post('/user/login', params)
    return data
}

// 获取用户信息
export const getUserInfo = async () => {
    return await request.get('/user/info')
}

// 更新用户信息
export const updateUserInfo = async (data) => {
    return await request.put('/user/update', data)
}

// 发送验证码
export const sendVerifyCode = async (phone) => {
    await new Promise(resolve => setTimeout(resolve, 500))
    return true
}

// 退出登录
export const userLogout = async () => {
    return await request.get('/user/logout')
}
